package descentFly.app.managePanel.chat
{
	import UIFree.controls.uif_maskedArea;
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import descentFly.app.df_block;
	import descentFly.app.df_component;
	import descentFly.app.scrollBar.df_scrollBarV;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	public class df_turnList extends df_block {
		private var _mask		: uif_ecomponent;
		private var _scrollArea	: df_turnScrollArea;
		private var _scrollBar	: df_scrollBarTurn;
		
		public function df_turnList(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='list') {
			super(parent, ax, ay, awidth, aheight, styleClass);
		}
		
		protected function maskCreate(): void {
			var rect: Rectangle = getInner();
			_mask = new uif_ecomponent(this, rect.x, rect.y, rect.width, rect.height, 'white');
			addChild(_mask);
		}
		
		override protected function updateBounds(): uif_component {
			if (!_mask) maskCreate();
			_mask.setRect(getInner());
			return super.updateBounds();
		}
		
		override protected function createComponents(layer:df_component, inner:Rectangle):void {
			_scrollArea = new df_turnScrollArea(layer, inner.x, inner.y, inner.width - df_component.SCROLLBAR_WIDTH, style.scrollArea);
			_scrollArea.addEvent(uif_component.RESIZE, doScrollAreaResize);
			_scrollArea.mask = _mask;
			
			_scrollBar = new df_scrollBarTurn(layer, inner.x + inner.width - df_component.SCROLLBAR_WIDTH, inner.y, df_component.SCROLLBAR_WIDTH, inner.height, style.scrollBar);
			_scrollBar.max 		= 0;
			_scrollBar.visible 	= false;
			_scrollBar.addEvent(Event.CHANGE, doScrollBarChange);
		}
		
		protected function doScrollAreaResize(e: Event): void {
			if (_scrollArea.height > _mask.height) {
				var isLast: Boolean  = _scrollBar.value == _scrollBar.max; 
				_scrollBar.visible = true;
				_scrollBar.max = _scrollArea.height - _mask.height;
				if (isLast) _scrollBar.value = _scrollBar.max;
			} else {
				_scrollBar.visible 	= false;
			}
		}
		
		protected function doScrollBarChange(e: Event): void {
			_scrollArea.fx('y', _scrollArea.y, -_scrollBar.value).start();
		}
		
		public function get scrollArea(): df_turnScrollArea {
			return _scrollArea;
		}
	}
}